package fr.inria.arles.temperatureManagement.queryProcessor.query;

import java.sql.ResultSet;
import java.sql.SQLException;

import static fr.inria.arles.temperatureManagement.utility.Utility.*;

/**
 * A Query to retrieve the current reference temperate setting.
 */
public class RFIDQuery extends AbstractQuery {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.inria.arles.tempManagement.queryProcessor.query.AbstractQuery#execute
	 * (java.lang.String[])
	 */
	@Override
	public String execute(String[] args) throws ClassNotFoundException,
			SQLException {
		ResultSet rs = executeQuery("SELECT ID,TEMP FROM TEMPERATURE "
				+ "WHERE RFID=? AND PARTITION=?", args);
		if (rs.next()) {
			return encode("true", rs.getString("ID"), rs.getLong("TEMP") + "");
		} else {
			return encode("true", "-1");
		}
	}

}
